import Vue from 'vue'
const mutations = {
  /*-------------系统--------------*/
  setNetwork(state, payload) {
    state.network = payload
  },
  setGFNetwork(state, payload) {
    state.GFNetwork = payload
    if (payload === true) {
      state.aiVoiceRecognition.isDisabled = false
    } else {
      state.aiVoiceRecognition.isDisabled = true
      state.aiVoiceRecognition.status = false
    }
  },
  // 修改语言
  setLang(state, payload) {
    state.lang = payload
  },
  /*-------------面板--------------*/
  // 控制面板开关状态切换
  setPanelStatus(state, payload) {
    state.isPanelOpen = payload
  },
  // 设置当前激活的tab
  setActiveTab(state, payload) {
    state.activeTab = payload
  },
  // 设置禁用的tab
  setDisabledTabs(state, payload) {
    state.disabledTabs = payload
  },

  // 设置默认开启
  setBlockDefaultOpen(state, payload) {
    if (Array.isArray(payload)) {
      state.collapseData.defaultOpen = payload
    } else {
      state.collapseData.defaultOpen = [payload]
    }
  },
  // 控制是否只展开一个
  setBlockUniqOpen(state, payload) {
    if (typeof payload === 'boolean') {
      state.collapseData.uniqueOpened = payload
    }
  },
  // 设置组信息，初始化组
  setBlockGroupInfo(state, payload) {
    Vue.set(state.collapseData.group, payload.name, payload.data)
  },
  // 向组中添加数据
  addBlockGroupInfo(state, payload) {
    let arr = state.collapseData.group[payload.name]
    arr.push(payload.data)
    state.collapseData.group[payload.name] = [...new Set(arr)]
  },
  // 移除组里的数据 one by one
  removeBlockInfo(state, payload) {
    if (!payload.data) {
      state.collapseData.group[payload.name] = []
    } else {
      state.collapseData.group[payload.name].splice(
        state.collapseData.group[payload.name].indexOf(payload.data),
        1
      )
    }
  },
  // 只展开一个时候移除数据 replase the data in the array
  removeBlockUniqInfo(state, payload) {
    state.collapseData.group[payload.name].splice(0, 1, payload.data)
  },
  // 最多保留一个展开
  removeBlockInfoLeftOne(state, payload) {
    state.collapseData.group[payload.name].splice(1)
  },

  /*-------------AI--------------*/
  // 语音合成开关
  setAiVoiceFeedback(state, v) {
    // 开启语音合成之前清除所有保留的语音文字
    state.synthesisText = ''
    state.aiVoiceFeedback.status = v
  },
  // 提交文字
  setAiSynthesisText(state, payload) {
    state.synthesisText = payload + `_${Date.now()}`
  },
  // 设置语音合成音量
  setAiSynthesisVolume(state, payload) {
    state.synthesisVolume = payload
  },
  // 设置语音合成语速
  setAiSynthesisRate(state, payload) {
    state.synthesisRate = payload
  },
  // 语音识别开关
  setAiVoiceRecognition(state, v) {
    state.aiVoiceRecognition.status = v
  },
  // 提交识别结果 recognizedResult
  setAiRecognizedResult(state, payload) {
    state.recognizedResult = payload
  },
  // 人脸识别开关
  setAiFaceRecognition(state, v) {
    state.aiFaceRecognition.status = v
  },
  setAiFaceRecognitionCount(state, v) {
    state.aiFaceRecognitionCount = v
  },
  setAiGestureRecognition(state, v) {
    state.aiGestureRecognition.status = v
  },
  /*-------------地图管理--------------*/
  setMapType(state, v) {
    state.mapType = v
  },
  /*-------------监控--------------*/
  setMonitorPanelId(state, payload) {
    state.monitorPanelId = payload
  },
  /*-------------控制台--------------*/
  setConsolePanelLog(state, payload) {
    state.consolePanel.log = payload
  },
  setConsolePanelVuex(state, payload) {
    state.consolePanel.vuex = payload
  },
  /*-------------授权信息--------------*/
  setLicense(state, payload) {
    state.license = payload
  }
}

export default mutations
